<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '新增' : '查看'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="30%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @submit.native.prevent="dataFormSubmit()" label-width="100px">
    <el-form-item label="外链类型:" prop="outerType">
      <!-- <el-input v-model="dataForm.outerType" placeholder="外链跳转类型"></el-input> -->
      <el-select v-model="dataForm.outerType" placeholder="商品状态" style="width: 260px">
				<el-option label="商品分类" value="0" ></el-option>
				<el-option label="联盟店分类" value="1" ></el-option>
				<el-option label="活动" value="2" ></el-option>
        <el-option label="外链" value="3" ></el-option>
				<el-option label="店铺" value="4" ></el-option>
				<el-option label="专题" value="5" ></el-option>
        <el-option label="无跳转" value="6" ></el-option>
				<el-option label="商品" value="7" ></el-option>
				<el-option label="品牌" value="8" ></el-option>
        <el-option label="特殊处理" value="12" ></el-option>
				<el-option label="分享" value="13" ></el-option>
				<el-option label="分类导航页" value="14" ></el-option>
        <el-option label="商城一级分类" value="17" ></el-option>
				<el-option label="采购" value="18" ></el-option>
			</el-select>
    </el-form-item>
    <!-- <el-form-item label="跳转地址" prop="outerUrl">
      <el-input v-model="dataForm.outerUrl" placeholder="跳转地址"></el-input>
    </el-form-item> -->
    <!-- <el-form-item label="是否启用（0：不启用；1：启用）" prop="isEnable">
      <el-input v-model="dataForm.isEnable" placeholder="是否启用（0：不启用；1：启用）"></el-input>
    </el-form-item> -->
    <el-form-item label="名称:" prop="outerTitle">
      <el-input v-model="dataForm.outerTitle" placeholder="名称" style="width: 260px"></el-input>
    </el-form-item>
    <el-form-item label="排序:" prop="seq">
      <el-input type="number" v-model="dataForm.seq" placeholder="排序" style="width: 260px"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          outerType: '',
          isEnable: '',
          seq: '',
          outerTitle: '',
        },
        dataRule: {
          outerType: [
            { required: true, message: '外链跳转类型不能为空', trigger: 'blur' }
          ],
          seq: [
            { required: true, message: '排序不能为空', trigger: 'blur' }
          ],
          outerTitle: [
            { required: true, message: '名称不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/outer/getOuterChainById/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.outerType = data.data.outerType + ''
                this.dataForm.seq = data.data.seq
                this.dataForm.outerTitle = data.data.outerTitle
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/outer/${!this.dataForm.id ? 'addOuterChain' : 'modifyOuterChainById'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'outerType': this.dataForm.outerType,
                'seq': this.dataForm.seq,
                'outerTitle': this.dataForm.outerTitle
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
